package com.tianhao.luo.innerclasssingleton;

import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Date 2019/12/10
 * @Author tianhao.luo
 * @Description 静态内部类实现懒汉模式
 */
public class InnerClassSingleton implements Serializable {
    static final long serialVersionUID = 42L;

    /**
     * 通过静态内部类来实例化对象
     */
    private static class InnerClassHolder {
        private static InnerClassSingleton instance = new InnerClassSingleton();
    }

    /**
     * 私有化构造方法
     */
    private InnerClassSingleton(){}

    public static InnerClassSingleton getInstance() {
        return InnerClassHolder.instance;
    }

    Object readResolve() throws ObjectStreamException{
        return InnerClassHolder.instance;
    }

}
